C++ System Programming Cookbook by Onorato Vaticone

C++ System Programming Cookbook by Onorato Vaticone

Author:Onorato Vaticone [Onorato Vaticone]
Language: eng
Format: epub
Tags: COM051070 - COMPUTERS / Programming Languages / C++, COM011000 - COMPUTERS / Systems Architecture / General, COM046030 - COMPUTERS / Operating Systems / UNIX
Publisher: Packt
Published: 2020-02-21T13:07:35+00:00


constexpr auto MAX_ITEM_IN_QUEUE = 5;

struct QueueInfo

{

sem_t mutex;

sem_t full;

sem_t empty;

std::vector<int> queue;

};

Now, let's write the code for producer:

void* producer(void *arg)

{

QueueInfo* info = (QueueInfo*)arg;

std::cout << "Thread Producer Started ... " << std::endl;

for (int i = 0; i < 1000; i++)

{

sem_wait(&info->full);

sem_wait(&info->mutex);

info->queue.push_back(i);

std::cout << "Thread Producer Started ... size = "

<< info->queue.size() << std::endl;

sem_post(&info->mutex);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.